package a.b.mvc6;

import jakarta.servlet.MultipartConfigElement;
import jakarta.servlet.ServletRegistration;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class MvcStarter extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        // 非Web配置
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        // Web配置
        return new Class[] {WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        // servlet 映射
        return new String[]{"/"};
    }

    /**
     * 进一步配置Servlet上下文
     * @param registration the {@code DispatcherServlet} registration to be customized
     */
    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {

        MultipartConfigElement configElement = new MultipartConfigElement(
                "C:/tmp", // 临时上传地址
                5_000_000, // 单个文件最大大小
                200_000_000, // 表单最大大小
                0 // 值为零表示必须始终将文件写入磁盘
        );
        registration.setMultipartConfig(configElement);
    }
}
